home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / setpgms.zip / SETREAD.ASM < prev    next >
Assembly Source File  |  1986-12-26  |  14KB  |  371 lines

  1.                page     64,132
  2.  
  3.                ;Copyright 1986, Arnold B. Krueger
  4.                ;All rights reserved. Contact "ARNY KRUEGER"
  5.                ;at the EXEC-PC BBS (414-964-5160) for permission 
  6.                ;to use commercially.
  7.  
  8.                ;SETREAD reads the keyboard and places what it reads into the
  9.                ;environment variable READSTR. Usage is:
  10.                ;
  11.                ;              SETREAD  [flags] [name] [flags]
  12.                ;            
  13.                ;              "name" is the name of the environment variable set.
  14.                ;              if none is supplied then READSTR is used.
  15.                ;         
  16.                ;flags are: /U - make input upper case
  17.                ;           /L - make input lower case
  18.                ;           /F - read a single keystroke
  19.                ;                honors typewriter keys, f1-f9
  20.                ;
  21.                ;You can then refer to the named string in .BAT files
  22.                ;    using its name delimited by percent signs ('%').
  23.                ;   
  24.                ;For example: 
  25.                ;     Echo name of program to run:
  26.                ;     SETREAD  
  27.                ;     echo  running: %readstr%
  28.                ;     %readstr%
  29.  
  30.                ;errorlevels are:
  31.                ;               0  if all goes well
  32.                ;               0  if the environment is out of space
  33.                ;                  (an error message will be typed by DOS)
  34.                ;               1  not at DOS 2.0 or above
  35.                ;               2  for SETREAD detected errors:
  36.                ;                        (an error message will be typed)
  37.                ;               3  for reading a null string
  38.                ;                        (no error message or alteration
  39.                ;                         of the environment)
  40.                ;               4  for ctrl-break
  41.                ;                        (no error message or alteration
  42.                ;                         of the environment)
  43.  
  44. code_seg       segment para public 
  45.                assume  cs:code_seg,ds:code_seg,ss:code_seg,es:code_seg
  46.                extrn   env_set:near
  47.                org     80h
  48. psp_parml      db      ?                    ;length of parms
  49. psp_parm       db      ?                    ;actual parms
  50.  
  51.                org     100h                 ; .COM file format
  52. main:          jmp     main_start           ; Skip around data declarations
  53. copyright      db      'Copyright 1986, Arnold B. Krueger GPW, MI 48236'
  54.  
  55. beep           equ     07
  56. cr             equ     13
  57. escape         equ     27
  58. lf             equ     10
  59.  
  60. set_string     db      'READSTR'
  61. set_length     equ     $-set_string
  62.  
  63. release_error  db    1,'Need at least DOS 2.0 to run SETREAD',cr,lf,'$'
  64. set_error      db    2
  65. crlf           db    cr,lf,'$'
  66.  
  67. scan_for_word   proc near           ;proc to scan es:di for contents of AX
  68.                                     ;   CX is length
  69.                                     ;at exit if found:  es:di points to word
  70.                                     ;                   cf is set
  71.                                     ;                   cx as at entry
  72.                                     ;        not found  es:di points to string
  73.                                     ;                   cf  not set
  74.                 push cx             ;                   cx as at entry
  75.                 push di 
  76.                 cmp  cx,2
  77.                 jb   scan_for_miss
  78.  
  79. scan_for_loop:  scasw               ;compare word to AX
  80.                 jz    scan_for_hit
  81.                 dec   di            ;back up a byte
  82.                 loop  scan_for_loop
  83.  
  84.                 pop   di            ;missed it
  85.                 pop   cx
  86. scan_for_miss:
  87.                 clc                 ;set not found flag
  88.                 jmp   scan_for_exit
  89. scan_for_hit:                       ;back up over string
  90.                 dec   di
  91.                 dec   di
  92.                 pop   cx            ;actually di data
  93.                 pop   cx
  94.                 stc                 ;set found flag
  95.  
  96. scan_for_exit:  ret
  97. scan_for_word   endp
  98.  
  99. scan_switches_switch     db  0     ;flag byte checked, as follows:
  100.  
  101. scan_switches_switches:            ;list of switches searched for
  102.                     db  '/u'
  103. switch_upper        equ 40h        ;translate to upper case
  104.                     db  switch_upper   
  105.  
  106.                     db  '/l'
  107. switch_lower        equ 20h        ;translate to lower case
  108.                     db  switch_lower
  109.  
  110.                     db  '/f'
  111. switch_fkey         equ 10h        ;accept as input a single keystroke
  112.                     db  switch_fkey
  113.  
  114. switch_list_length  equ  $-scan_switches_switches
  115. switch_count        equ  switch_list_length / 3 
  116.  
  117. scan_switches   proc  near          ;scan parameters for switches
  118.                 push  ax            ; Switches are defined above as word of text
  119.                 push  cx            ;       and byte containing switch bit(s)
  120.                 push  di            ; Switch text is blanked out of parameter
  121.                 push  es            ; If switch byte has hi bit turned on,
  122.                 push  si            ;       switch bit(s) are turned off
  123.  
  124.                 mov   cx,switch_count     ;number of switches to test for
  125.                 push  cs                  ;get PSP address
  126.                 pop   es                  ;    in ES
  127.                 mov   si,offset scan_switches_switches
  128. scan_switches_loop:
  129.                 push  cx                  ;save loop counter
  130.                 lodsw                     ;get flag to scan for into AX
  131.                 cmp   ah,'Z'              ;are we scanning for lower case?
  132.                 ja    scan_lower          ;if so, great
  133.                                           ;protect me from sloppy programmers (!)
  134.                 or    ah,32               ;if not, make lower.
  135. scan_lower: 
  136.                 mov   di,offset psp_parm  ;get where to scan
  137.                 xor   cx,cx
  138.                 mov   cl,[psp_parml]      ;get length of parm string
  139.                 jcxz  scan_switches_none  ;if no parms, no flags set
  140.  
  141.                 call  scan_for_word       ;scan for indicated flag
  142.                 jc    scan_case           ;if we got it, modify switches
  143.  
  144.                 and   ah,255-32           ;make upper case
  145.                 call  scan_for_word       ;scan for indicated flag in upper case
  146.  
  147. scan_case:
  148.                 lodsb                     ;put flag byte value in AL
  149.                 jnc   scan_switches_loop_inc ;skip including it, if not found
  150.  
  151.                 test  al,80h              ;if hi bit of flag is off
  152.                 jz    scan_turn_on        ;we are turning switch bits on
  153.                                           ;otherwise, turn them off by:
  154.  
  155.                 xor   al,0ffh             ;invert bits in flag     
  156.                 and   scan_switches_switch,al  ;and use to turn off switch bits
  157.                 jmp   scan_blank
  158.  
  159. scan_turn_on:
  160.                 or    scan_switches_switch,al  ;add into switch bit into switch byte
  161. scan_blank:
  162.                 mov   es:[di],'  '        ;blank out parm
  163. scan_switches_loop_inc:
  164.                 pop   cx                  ;restore loop counter
  165.                 loop  scan_switches_loop
  166.  
  167.                 jmp   scan_switches_exit
  168.  
  169. scan_switches_none:
  170.                 pop   cx                  ;clean up stack
  171. scan_switches_exit:
  172.                 pop   si
  173.                 pop   es
  174.                 pop   di
  175.                 pop   cx
  176.                 pop   ax
  177.                 ret
  178. scan_switches   endp
  179.  
  180. read_byte       proc near                ;read single byte into area at ds:di
  181.                                          ;return length of symbol in cx
  182.                 push  ax                 ;save registers
  183.                 push  dx
  184. read_byte_in:
  185.                 mov  ah,08h              ;dos int to read a key, no echo
  186.                 int  21h
  187.                 cmp  al,0                ;scan code returned?
  188.                 jnz